package com.spring.service;

import com.spring.dao.IAccountDao;
import com.spring.model.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Transactional//开启事务

@Service
public class AccountServiceImpl implements IAccountService {
    @Autowired
    private IAccountDao accountDao;
    //事务注解
    @Transactional(isolation = Isolation.REPEATABLE_READ,propagation = Propagation.REQUIRED)
    @Override
    public void transfer(Integer from, Integer to, Double money) {
      Account score=accountDao.findById(from);
      Account target=accountDao.findById(to);
      accountDao.updateMoneyById(to,score.getMoney()+money);
      accountDao.updateMoneyById(from,target.getMoney()-money);
    }

    @Override
    public void get() {

    }
}
